﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using AppLayer;
using SpotItComponents;
using SpotItServerAPI;

namespace SpotIt
{
    /// <summary>
    /// Interaction logic for SpotIt_Multi_CreateGame.xaml
    /// </summary>
    public partial class SpotIt_Multi_CreateGame : Window
    {
        public Services services { get; set; }
        public Session session { get; set; }
        private GameMonitor myGameMonitor;

        public SpotIt_Multi_CreateGame()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            /*
            gameTypeComboBox.Items.Add("Hot Potato");
            gameTypeComboBox.Items.Add("Posion");
            gameTypeComboBox.Items.Add("Well");
            gameTypeComboBox.Items.Add("Tower");

            gameTypeComboBox.SelectedItem = "Tower";

            List<PlayingDeck> playingDecks = new List<PlayingDeck>();
            OperationResult result = services.deckManager.AvailablePlayingDecks(session);
            if (result.Success)
                playingDecks = result.Data as List<PlayingDeck>;

            deckDataGrid.ItemsSource = playingDecks;
             */ 

        }

        private void createButton_Click(object sender, RoutedEventArgs e)
        {
            
            PlayingDeck selectedDeck = (PlayingDeck)deckDataGrid.SelectedItem;

            GameType gameType;
            switch(gameTypeComboBox.SelectedIndex)
            {
                case 0:
                    gameType = GameType.HotPotato;
                    break;
                case 1:
                    gameType = GameType.Poison;
                    break;
                case 2:
                    gameType = GameType.Well;
                    break;
                case 3:
                    gameType = GameType.Tower;
                    break;

                default:
                    gameType = GameType.Tower;
                    break;
            }

            myGameMonitor = new GameMonitor();

            OperationResult result = services.gameManager.CreateGame(session, selectedDeck, gameType, titleTextBox.Text, (int)mublerOfPlayerSlider.Value, myGameMonitor);
            if (result.Success)
            {
                Spotit_Multi_waitroom waitRoomWindow = new Spotit_Multi_waitroom(session, services);
                waitRoomWindow.ShowDialog();
                this.Close();
            }
            
        }

        private void mublerOfPlayerSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            sliderCount.Content = mublerOfPlayerSlider.Value;
        }
        
        
    }
}
